package com.example.time_planner.drawer_menu;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.time_planner.R;

public class NavigationDrawerAdapter extends ArrayAdapter<NavigationItem> {

	private Context context;
	private int resource;
	private List<NavigationItem> listOfItems;
	private TextView textView;
	private ImageView iconView;

	public NavigationDrawerAdapter(Context context, int resource,
			List<NavigationItem> objects) {
		super(context, resource, objects);
		this.context = context;
		this.resource = resource;
		this.listOfItems = objects;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = LayoutInflater.from(getContext());

		View view = convertView;

		if (view == null) {

			view = inflater.inflate(resource, parent, false);
			iconView = (ImageView) view.findViewById(R.id.imageView);
			textView = (TextView) view.findViewById(R.id.navigationTextView);

			iconView.setImageResource(listOfItems.get(position).getIcon());
			textView.setText(listOfItems.get(position).getText());

		}

		iconView.setImageResource(listOfItems.get(position).getIcon());
		textView.setText(listOfItems.get(position).getText());

		return view;
	}

}
